package com.hethongviet.vending.model;

import java.util.Timer;
import java.util.TimerTask;
import com.hethongviet.vending.network.OnTimeOutListener;
import android.util.Log;

public class Transaction extends Model
{
	private int idSent = 0;
	private String methodSent = "";
	private Model model = null;

	private String messageSent = "";
	private String messageReceived = "";

	private OnTimeOutListener onNetworkTimeOutListener = null;
	private boolean isFail = false;

	private Timer timerOut = null;

	public Transaction()
	{
		super();
	}

	public int getIdSent()
	{
		return idSent;
	}

	public Transaction(OnTimeOutListener failListener, int timeOut)
	{
		onNetworkTimeOutListener = failListener;
		TimerTask timerTask = new TimerTask()
		{

			@Override
			public void run()
			{
				isFail = true;
				Log.d("Transaction", "TIME OUT SMS!!!!!!!!!!!!!");

				if (onNetworkTimeOutListener != null)
					onNetworkTimeOutListener.onNetworkTimeOut(Transaction.this);
			}
		};

		timerOut = new Timer();
		timerOut.schedule(timerTask, timeOut);
	}

	public void success()
	{
		isFail = false;
		if (timerOut != null)
		{
			timerOut.cancel();
			timerOut = null;
		}
	}

	public void setIdSent(int idSent)
	{
		this.idSent = idSent;
	}

	public String getMethodSent()
	{
		return methodSent;
	}

	public void setMethodSent(String methodSent)
	{
		this.methodSent = methodSent;
	}

	public Model getModel()
	{
		return model;
	}

	public void setModel(Model model)
	{
		this.model = model;
	}

	public String getMessageSent()
	{
		return messageSent;
	}

	public void setMessageSent(String messageSent)
	{
		this.messageSent = messageSent;
	}

	public String getMessageReceived()
	{
		return messageReceived;
	}

	public void setMessageReceived(String messageReceived)
	{
		this.messageReceived = messageReceived;
	}

	public boolean isFail()
	{
		return isFail;
	}

	public void setFail(boolean isFail)
	{
		this.isFail = isFail;
	}
}
